<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Test</title>
<style type="text/css">
body{ font-size:12px; line-height:150%;}
dl{ margin:6px 20px; border-bottom:1px #DDDDDD dashed;}
dl dt b{display:inline-block; width:30px; color:#FF0000;}
dl dt span{ display:inline-block; width:180px; font-size:14px; font-weight:bold; color:#666666}
dl dd{ margin:10px 16px 6px; color:#003300;}
</style>
</head>
<body>
    <div id="comments">
    </div>
    <div align="right">
      <p>
      I'm in the <i>iframe.html</i> page
      <select id="step"></select>
      <input id="more" type="button" value="More..（iframe 页面控制）" />
      </p>
    </div>
</body>
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="function.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(window.parent.document).find("iframe[id='iframe']").height( $("#comments").height()+50 ); //初始化iframe高度
	for( x=1;x<=50;x++ ){
    	$("#step").append('<option value="'+ x +'">'+ x +'</option>');
	}
	n=1;
	$("#more").click(function(){
	    for(i=0;i< $("#step").val() ;i++){
			$.ajax({
				type: "GET",
				dataType: "json",
				url: "ajax.php?t=" + new Date().getTime(), //防止ajax缓存
				data: "s="+ $("#step").val() + "&n=" + (n++),
				timeout: 10000,
				success: function(d){ 
				  $("#comments").append(html(d));
				  //将ajax获取的数据动态显示在div里
				  
                  $(window.parent.document).find("iframe[id='iframe']").height( $("#comments").height()+50 );
				  //取得父页面 id = iframe 的 iframe，设置其高度为 comments 高度 + 50px
				}
			});	
		}
	
	})

});

</script>
</html>
